//
//  BDShopHeaderView.m
//  BadBoy
//
//  Created by wen on 2017/3/16.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDShopHeaderView.h"
#import "YYStarView.h"
#import "SDCycleScrollView.h"

@interface BDShopHeaderView ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) YYStarView *starView;
@property (nonatomic, strong) UILabel *EvaluateNum;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) SDCycleScrollView *coverImage;
@property (nonatomic, strong) NSArray *imageAray;
@property (nonatomic, strong) UILabel *rangLabel;

@end

@implementation BDShopHeaderView

+ (CGFloat)getHeightWithModel:(BDShopDetailModel *)model{
    if (model.images.count == 0) {
        return 44 + 5;
    }
    return 44 + 5 + 150 * kBDScreenWidth / 375;
}

- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSArray *)array{
    if (self = [super initWithFrame:frame]) {
        self.imageAray = array;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)configeWithModel:(BDShopDetailModel *)model{
    //商家名称
    self.nameLabel.text = model.title;
    //评分
    [self.starView displayRating:model.score];
    self.EvaluateNum.text = [NSString stringWithFormat:ASLocalizedString(@"%ld人评价"),model.comment];
    //        //人均消费
    self.timeLabel.text = [NSString stringWithFormat:ASLocalizedString(@"人均: %ld元"), model.consumption];
    //        //距离
    if (model.distance < 0.5) {
        self.rangLabel.text = @"< 500m";
    }else{
        self.rangLabel.text = [NSString stringWithFormat:@"%.1fkm",model.distance];
    }
    if (model.images.count) {
        self.coverImage.imageURLStringsGroup = model.images;
//        [self.coverImage setImageArray:model.images];
//        [self.coverImage setContentMode:LunboImageViewContnetModeFull];
//        [self.coverImage starLunbo];
    }else{
        self.coverImage.hidden = YES;
    }
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = KBDNameColor;
        _nameLabel.font = [UIFont systemFontOfSize:16];
        [self addSubview:_nameLabel];
    }
    return _nameLabel;
}
-(YYStarView *)starView{
    if (!_starView) {
        _starView = [[YYStarView alloc] init];
        [self addSubview:_starView];
    }
    return _starView;
}

-(UILabel *)EvaluateNum{
    if (!_EvaluateNum) {
        self.EvaluateNum = [[UILabel alloc]init];
        _EvaluateNum.textColor = kBDTimeColor;
        _EvaluateNum.font = [UIFont systemFontOfSize:13];
        [self addSubview:_EvaluateNum];
    }
    return _EvaluateNum;
}
-(UILabel *)timeLabel{
    if (!_timeLabel) {
        self.timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = kBDTimeColor;
        _timeLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:_timeLabel];
    }
    return _timeLabel;
}
- (SDCycleScrollView *)coverImage{
    if (!_coverImage) {
        self.coverImage = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kBDScreenWidth, 150 * kBDScreenWidth / 375) delegate:self placeholderImage:[UIImage imageNamed:@"shop_pic"]];
        [self addSubview:_coverImage];
    }
    return _coverImage;
}

-(UILabel *)rangLabel{
    if (!_rangLabel) {
        self.rangLabel = [[UILabel alloc]init];
        _rangLabel.textColor = kBDTimeColor;
        _rangLabel.font = [UIFont systemFontOfSize:13];
        _rangLabel.textAlignment = NSTextAlignmentRight;
//        [self addSubview:_rangLabel];
    }
    return _rangLabel;
}

//按钮点击
-(void)callButtonPress:(UIButton *)sender{
//    if (self.delegate && [self.delegate respondsToSelector:@selector(BDTwoTableViewCellcallButtonPress:)]) {
//        [self.delegate BDTwoTableViewCellcallButtonPress:sender];
//    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.nameLabel.size= CGSizeMake(self.width - 10, self.nameLabel.font.pointSize);
    self.nameLabel.left = 10;
    self.nameLabel.top = 10;
    
    self.rangLabel.size = CGSizeMake([self.rangLabel.text widthWithFont:self.rangLabel.font], self.rangLabel.font.pointSize+1);
    self.rangLabel.right = self.width - 10;
    self.rangLabel.centerY = self.nameLabel.centerY;
    
    [self.starView setStarWidth:12 starSpace:1.2 andDelegate:nil];
    self.starView.left = self.nameLabel.left;
    self.starView.top = self.nameLabel.bottom + 5;
    
    self.EvaluateNum.size =CGSizeMake([self.EvaluateNum.text widthWithFont:self.rangLabel.font], self.EvaluateNum.font.pointSize + 1);
    self.EvaluateNum.left = self.starView.right + 5;
    self.EvaluateNum.centerY = self.starView.centerY;
    
    self.coverImage.top = self.EvaluateNum.bottom + 5;
    
    // BDLog(ASLocalizedString(@"当前底部按钮位置：%f"), self.EvaluateNum.bottom);
}

@end
